Imports System.Data.SqlClient
Public Class Insurances
    Public Shared Function GetInsurance() As DataTable
        Str = "SELECT INSURANCE_ID,EMPLOYEE_NAME=ENGLISH_NAME +' ( '+KHMER_NAME+' )',OCCUR_DATE,OPEN_CLAIM,TYPE_OF_CLAIM,AMOUNT,MODIFY_BY,DESCRIPTION,COMPANY,ACTIVE FROM  VIEW_INSURANCE  WHERE ACTIVE=1 ORDER BY INSURANCE_ID ASC "

        Try


            Dim dataAdapter As SqlDataAdapter
            dataAdapter = New SqlDataAdapter(Str, CType(Dbinterface.Connection, SqlConnection))
            Dim dataTable As DataTable = New DataTable()
            dataAdapter.Fill(dataTable)
            Return dataTable
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
            Return Nothing
        End Try
    End Function
    Public Shared Sub AddInsurance(ByVal Ins As InsuranceInfo)

        CmdPro.Begin()

        Try

            CmdPro.Parameters("@employeeId") = Ins.employeeId
            CmdPro.Parameters("@occurDate") = Ins.occurDate
            CmdPro.Parameters("@openClaim") = Ins.openClaim
            CmdPro.Parameters("@typeOfClaim") = Ins.typeOfClaim
            CmdPro.Parameters("@amount") = Ins.amount
            CmdPro.Parameters("@userId") = Ins.userId
            CmdPro.Parameters("@description") = Ins.description
            CmdPro.Parameters("@company") = Ins.company
            CmdPro.Parameters("@active") = Ins.active
            Ins.InsuranceId = CmdPro.ExecuteNonQuery("InsertInsurance", "@id")
            CmdPro.Commit()

        Catch ex As Exception

            CmdPro.Rollback()

            MsgBox(ex.Message)

        End Try

    End Sub
    Public Shared Sub UpdateInsurance(ByVal Ins As InsuranceInfo)

        CmdPro.Begin()

        Try

            CmdPro.Parameters("@id") = Ins.InsuranceId
            CmdPro.Parameters("@employeeId") = Ins.EmployeeId
            CmdPro.Parameters("@occurDate") = Ins.occurDate
            CmdPro.Parameters("@openClaim") = Ins.openClaim
            CmdPro.Parameters("@typeOfClaim") = Ins.typeOfClaim
            CmdPro.Parameters("@amount") = Ins.amount
            CmdPro.Parameters("@userId") = Ins.userId
            CmdPro.Parameters("@description") = Ins.description
            CmdPro.Parameters("@company") = Ins.company
            CmdPro.Parameters("@active") = Ins.active
            Ins.InsuranceId = CmdPro.ExecuteNonQuery("UpdateInsurance")
            CmdPro.Commit()

        Catch ex As Exception

            CmdPro.Rollback()

            MsgBox(ex.Message)

        End Try


    End Sub
    Public Shared Sub DeleteInsurance(ByVal Ins As InsuranceInfo)
        CmdPro.Begin()
        Try
            CmdPro.Parameters("@id") = Ins.InsuranceId
            CmdPro.ExecuteNonQuery("DeleteInsurance")

            CmdPro.Commit()
        Catch ex As Exception
            CmdPro.Rollback()
            MsgBox(ex.Message)
        End Try
    End Sub

End Class